//package com.jdh.config;
//
//import com.alibaba.fastjson2.JSONArray;
//import com.jdh.model.User;
//import org.springframework.context.ApplicationEvent;
//import org.springframework.context.ApplicationListener;
//import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
//import org.springframework.stereotype.Component;
//import org.springframework.web.socket.messaging.SessionConnectEvent;
//import org.springframework.web.socket.messaging.SessionDisconnectEvent;
//
//import java.util.Map;
//
///**
// * @ClassName: WebSocketConnectListener
// * @Author: jdh
// * @CreateTime: 2024-01-11
// * @Description:
// */
//@Component
//public class WebSocketConnectListener implements ApplicationListener<ApplicationEvent> {
//
//    @Override
//    public void onApplicationEvent(ApplicationEvent event) {
//        System.err.println("all -> class :" + event.getClass());
//        if (event instanceof SessionConnectEvent) {
//            StompHeaderAccessor headerAccessor = StompHeaderAccessor
//                    .wrap(((SessionConnectEvent) event).getMessage());
//            SessionConnectEvent event1 = (SessionConnectEvent) event;
//            String sessionId = event1.getMessage().getHeaders().get("simpSessionId").toString();
//            User user = JSONArray.parseArray(
//                    ((Map) event1.getMessage().getHeaders().get("nativeHeaders")).get("user").toString(), User.class).get(0);
//            System.out.println("Connect 用户成功连接：" + sessionId + "; 用户:" + user);
//        } else if (event instanceof SessionDisconnectEvent) {
//            StompHeaderAccessor headerAccessor = StompHeaderAccessor
//                    .wrap(((SessionDisconnectEvent) event).getMessage());
//            SessionDisconnectEvent event1 = (SessionDisconnectEvent) event;
//            String sessionId = event1.getMessage().getHeaders().get("simpSessionId").toString();
//            // 在此处执行连接断开时的逻辑处理
//            System.out.println("Connect 用户断开连接：" + sessionId);
//        }
//    }
//}
